<?php

require_once APPLICATION_PATH . '/../library/tcpdf/examples/tcpdf_include.php';

class Uuch_Tcpdf extends TCPDF {

    public function Header() {
        
    }

    public function Footer() {
    }

    public function printEUBmainPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf) {
        $this->print_addpage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf) ;
        if($billItem->CityBy->Word == Application_Model_city::EUB_US){ //美国
            $pdf->Image('admins/images/eub/eubFrom.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 2, 20, 20, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 1, false, false, false);
            $pdf->Image('admins/images/eub/EUBFlag.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 24, $PageRegions[$Labelflag][$pagenum]['yt'] + 2, 50, 20, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);

            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 76, $PageRegions[$Labelflag][$pagenum]['yt'] + 3);
            $pdf->SetFont('helvetica', '', 8);
            $pdf->MultiCell(22, 5, 'Airmail
Postage Paid
China Post', 1, 'L', 1, 1, '', '', true);
            $pdf->SetFontSize(20);

            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 84, $PageRegions[$Labelflag][$pagenum]['yt'] + 14.5);
            $pdf->Cell(0, 0, '1', 0, 0, 'L', 0, '', 0);
            $pdf->SetFontSize(8);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 21);
            $pdf->Cell(0, 0, 'From:', 0, 0, 'L', 0, '', 0);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->MultiCell(54, 24, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->Cell(0, 0, "UUCH", 0, 0, 'L', 0, '', 0);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 29);
            $pdf->MultiCell(52, 5, 'Building 2 YouQi warehouse ShanCheng logistics park Tangtou  avenue  Shiyan street Baoan District ShenZhen GuangDong China 518108', 0, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 45);
            $pdf->SetFont('helvetica', 'I', 4);
            $pdf->MultiCell(52, 5, 'Customs information avaliable on attached CN22. 
USPS Personnel Scan barcode below for delivery event information', 0, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 55, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->MultiCell(44, 27, '', 1, 'L', 1, 1, '', '', true);
            $pdf->write1DBarcode($billItem->ConPostCode, 'C128', $PageRegions[$Labelflag][$pagenum]['xt'] + 54, $PageRegions[$Labelflag][$pagenum]['yt'] + 25, 48, 28, 1, $PageRegions['1DBarcode']['noborder'], 'N');
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1,$PageRegions[$Labelflag][$pagenum]['yt'] + 50);
            $pdf->SetFont('helvetica', '', 16);
            $pdf->Cell(20, 20, 'TO:', 1, 0, 'C', 0, '', 0);
            $pdf->SetFontSize(8);
            $pdf->SetX($PageRegions[$Labelflag][$pagenum]['xt'] + 21);
            $pdf->MultiCell(78, 20, "{$billItem->Consignee}
            {$billItem->conAdd} {$billItem->UserCity->ename} {$billItem->conPostCode}", 1, 'L', 1, 1, '', '', true);
            $pdf->SetFontSize(9);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 13, $PageRegions[$Labelflag][$pagenum]['yt'] + 72);
            $pdf->Cell(75, 0, 'USPS DELIVERY CONFIRMATION ®', 0, 0, 'C', 0, '', 0);

            $pdf->write1DBarcode($agentNo, 'C128', $PageRegions[$Labelflag][$pagenum]['xt'] + 11, $PageRegions[$Labelflag][$pagenum]['yt'] + 75, 80, 25, 1, $PageRegions['1DBarcode']['noborder'], 'N');
            $pdf->SetFontSize(8);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 67, $PageRegions[$Labelflag][$pagenum]['yt'] + 45.8);
            $pdf->Cell(0, 0, 'ZIP', 0, 0, 'L', 0, '', 0);
        } else if ($billItem->CityBy->Word == Application_Model_city::EUB_AU || $billItem->CityBy->Word == Application_Model_city::EUB_CA){ 
            if($billItem->CityBy->Word == Application_Model_city::EUB_AU){//澳大利亚
                $pdf->Image('admins/images/eub/AU_Title.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 4, $PageRegions[$Labelflag][$pagenum]['yt'] + 4.5, 27 , 17, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 0, false, false, false);
            } else if ($billItem->CityBy->Word == Application_Model_city::EUB_CA){ // 加拿大
                $pdf->Image('admins/images/eub/CA_Title.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 4, $PageRegions[$Labelflag][$pagenum]['yt'] + 4.5, 27 , 17, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 0, false, false, false);
            }
            $pdf->Image('admins/images/eub/AU_Flag.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 38, $PageRegions[$Labelflag][$pagenum]['yt'] + 4.7, 40, 16.3, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);

            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 76, $PageRegions[$Labelflag][$pagenum]['yt'] + 3);
            $pdf->SetFont('helvetica', '', 8);
            $pdf->SetFontSize(13);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 90, $PageRegions[$Labelflag][$pagenum]['yt'] + 16.5);
            $pdf->Cell(8, 0, 'A', 1, 0, 'C', 0, '', 0);
            $pdf->SetFontSize(8);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 21);
            $pdf->Cell(0, 0, 'From:', 0, 0, 'L', 0, '', 0);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->MultiCell(98, 24, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->Cell(0, 0, "UUCH", 0, 0, 'L', 0, '', 0);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 29);
            $pdf->MultiCell(48, 5, ' Building 2 YouQi warehouse ShanCheng logistics park Tangtou  avenue  Shiyan street Baoan District ShenZhen GuangDong China 518108', 0, 'L', 1, 1, '', '', true);
            $pdf->Image('admins/images/eub/PostExpress.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] +80 , $PageRegions[$Labelflag][$pagenum]['yt'] + 28, 14.5, 19.5, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1,$PageRegions[$Labelflag][$pagenum]['yt'] + 50);
            $pdf->SetFont('helvetica', '', 16);
            $pdf->Cell(20, 21, 'TO:', 1, 0, 'C', 0, '', 0);
            $pdf->SetFontSize(8);
            $pdf->SetX($PageRegions[$Labelflag][$pagenum]['xt'] + 21);
            $pdf->MultiCell(78, 21, "{$billItem->Consignee}
            {$billItem->conAdd} {$billItem->UserCity->ename} {$billItem->conPostCode}", 1, 'L', 1, 1, '', '', true);
            
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 71.3);
            $pdf->MultiCell(98, 30, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 71.6);
            $pdf->MultiCell(98, 30, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetFont('helvetica', 'B', 10);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 13, $PageRegions[$Labelflag][$pagenum]['yt'] + 72);
            $pdf->Cell(75, 0, 'TO BE SCANNED BY AUSTRALIA POST', 0, 0, 'C', 0, '', 0);
            
            $pdf->Image('admins/images/eub/ScanFlag.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] +3 , $PageRegions[$Labelflag][$pagenum]['yt'] + 79, 10, 12, 'JPG', 'javascript:void(0)', 'C', true, 150, '', false, false, 0, false, false, false);
            
            $pdf->write1DBarcode($agentNo, 'C128', $PageRegions[$Labelflag][$pagenum]['xt'] + 11, $PageRegions[$Labelflag][$pagenum]['yt'] + 75, 78, 25, 1, $PageRegions['1DBarcode']['noborder'], 'N');
            $pdf->SetFontSize(8);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 67, $PageRegions[$Labelflag][$pagenum]['yt'] + 45.8);
            
            $pdf->Image('admins/images/eub/NoSignatureFlag.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] +86 , $PageRegions[$Labelflag][$pagenum]['yt'] + 77, 11, 16.5, 'JPG', 'javascript:void(0)', 'C', true, 150, '', false, false, 0, false, false, false);
            
        } else if ($billItem->CityBy->Word == Application_Model_city::EUB_GB) { //英国
            $pdf->Image('admins/images/eub/GB_Title.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 4.5, 27 , 17, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 0, false, false, false);
            $pdf->Image('admins/images/eub/GB_Flag.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 34, $PageRegions[$Labelflag][$pagenum]['yt'] + 2.8, 40, 19.3, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);
            $pdf->Image('admins/images/eub/GB_TitleRight.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 78, $PageRegions[$Labelflag][$pagenum]['yt'] + 4.5, 20, 17, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);
            $pdf->SetFontSize(8);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 21);
            $pdf->Cell(0, 0, 'From:', 0, 0, 'L', 0, '', 0);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->MultiCell(98, 24, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->Cell(0, 0, "UUCH", 0, 0, 'L', 0, '', 0);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 29);
            $pdf->MultiCell(48, 5, ' Building 2 YouQi warehouse ShanCheng logistics park Tangtou  avenue  Shiyan street Baoan District ShenZhen GuangDong China 518108', 0, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1,$PageRegions[$Labelflag][$pagenum]['yt'] + 50);
            $pdf->SetFont('helvetica', '', 16);
            $pdf->Cell(20, 21, 'TO:', 1, 0, 'C', 0, '', 0);
            $pdf->SetFontSize(8);
            $pdf->SetX($PageRegions[$Labelflag][$pagenum]['xt'] + 21);
            $pdf->MultiCell(78, 21, "{$billItem->Consignee}
            {$billItem->conAdd} {$billItem->UserCity->ename} {$billItem->conPostCode}", 1, 'L', 1, 1, '', '', true);
            
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 71.3);
            $pdf->MultiCell(98, 30, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 71.6);
            $pdf->MultiCell(98, 30, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetFont('helvetica', '', 9);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 13, $PageRegions[$Labelflag][$pagenum]['yt'] + 72);
            $pdf->Cell(75, 0, 'Royal Mail No Delivery Signature or Scan', 0, 0, 'C', 0, '', 0);
            $pdf->write1DBarcode($agentNo, 'C128', $PageRegions[$Labelflag][$pagenum]['xt'] + 11, $PageRegions[$Labelflag][$pagenum]['yt'] + 75, 78, 25, 1, $PageRegions['1DBarcode']['noborder'], 'N');
            $pdf->SetFontSize(8);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 67, $PageRegions[$Labelflag][$pagenum]['yt'] + 45.8);
         } else if ($billItem->CityBy->Word == Application_Model_city::EUB_FR) { //法国
            $pdf->Image('admins/images/eub/FR_Title.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 3, 25 , 19, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 0, false, false, false);
            $pdf->Image('admins/images/eub/FR_Flag.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 28, $PageRegions[$Labelflag][$pagenum]['yt'] + 2.8, 48, 19.3, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);
            $pdf->Image('admins/images/eub/PostExpress.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 80, $PageRegions[$Labelflag][$pagenum]['yt'] + 2, 17, 22, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);
            $pdf->SetFontSize(8);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 21);
            $pdf->Cell(0, 0, 'DE:', 0, 0, 'L', 0, '', 0);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->MultiCell(98, 24, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->Cell(0, 0, "UUCH", 0, 0, 'L', 0, '', 0);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 29);
            $pdf->MultiCell(48, 5, ' Building 2 YouQi warehouse ShanCheng logistics park Tangtou  avenue  Shiyan street Baoan District ShenZhen GuangDong China 518108', 0, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 65, $PageRegions[$Labelflag][$pagenum]['yt'] + 26);
            $pdf->SetFont('helvetica', '', 16);
            $pdf->Cell(34, 24, "{$billItem->conPostCode}", 1, 0, 'C', 0, '', 0);
            
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1,$PageRegions[$Labelflag][$pagenum]['yt'] + 50);
            $pdf->SetFont('helvetica', '', 16);
            $pdf->Cell(21, 21, 'A:', 1, 0, 'C', 0, '', 0);
            $pdf->SetFontSize(8);
            $pdf->SetX($PageRegions[$Labelflag][$pagenum]['xt'] + 22);
            $pdf->MultiCell(58, 21, "{$billItem->Consignee}
            {$billItem->conAdd} {$billItem->UserCity->ename} {$billItem->conPostCode}", 0, 'L', 0, 0, '', '', true);
            $pdf->Image('admins/images/eub/FR_AddRight.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 77, $PageRegions[$Labelflag][$pagenum]['yt'] + 54, 20, 13, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);
            
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 70.8);
            $pdf->MultiCell(98, 28, "", 1, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 71);
            $pdf->MultiCell(98, 28, "", 1, 'L', 1, 1, '', '', true);
            $pdf->Image('admins/images/eub/FR_BarLeft.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 76, 14, 22, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);
            $pdf->SetFont('helvetica', '', 9);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 13, $PageRegions[$Labelflag][$pagenum]['yt'] + 72);
            $pdf->Cell(75, 0, 'CONFIRMATION DE DISTRIBUTION', 0, 0, 'C', 0, '', 0);
            $pdf->write1DBarcode($agentNo, 'C128', $PageRegions[$Labelflag][$pagenum]['xt'] + 12, $PageRegions[$Labelflag][$pagenum]['yt'] + 75, 76, 25, 1, $PageRegions['1DBarcode']['noborder'], 'N');
            $pdf->SetFontSize(8);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 67, $PageRegions[$Labelflag][$pagenum]['yt'] + 45.8);
            $pdf->Image('admins/images/eub/FR_BarRight.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 84, $PageRegions[$Labelflag][$pagenum]['yt'] + 76, 14, 22, 'JPG', 'javascript:void(0)', 'C', true, 300, '', false, false, 0, false, false, false);
        }
    }
    
    public function printEUBCustomsPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf) {
        $this->print_addpage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
        $pdf->Image('admins/images/eub/chinapostflag.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 5, $PageRegions[$Labelflag][$pagenum]['yt'] + 2, 30, 9, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 0, false, false, false);
        if($billItem->CityBy->Word == Application_Model_city::EUB_US){ //美国
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 9);
            $pdf->SetFont('helvetica', '', 5.5);
            $pdf->MultiCell(25, 5, 'IMPORTANT:
The item/parcel may be opened officially. Please print in English.', 0, 'L', 1, 1, '', '', true);
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 27, $PageRegions[$Labelflag][$pagenum]['yt'] + 10);
            $pdf->SetFont('helvetica', 'B', 14);
            $pdf->Cell(8, 7, '1', 1, 0, 'C', 0, '', 0);
        } else if ($billItem->CityBy->Word == Application_Model_city::EUB_AU){ //澳大利亚
            $pdf->Image('admins/images/eub/AU_A.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 3, $PageRegions[$Labelflag][$pagenum]['yt'] + 12, 20, 8, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 0, false, false, false);
        } else if ($billItem->CityBy->Word == Application_Model_city::EUB_CA) { //加拿大
            $pdf->Image('admins/images/eub/CA_A.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 3, $PageRegions[$Labelflag][$pagenum]['yt'] + 12, 20, 8, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 0, false, false, false);
        } else if ($billItem->CityBy->Word == Application_Model_city::EUB_GB) {
            $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 9);
            $pdf->SetFont('helvetica', '', 5.5);
            $pdf->MultiCell(25, 5, 'IMPORTANT:
The item/parcel may be
opened officially.
Please print in English.', 0, 'L', 1, 1, '', '', true);
        } else if ($billItem->CityBy->Word == Application_Model_city::EUB_FR) { //法国
            $pdf->Image('admins/images/eub/FR_A.jpg', $PageRegions[$Labelflag][$pagenum]['xt'] + 3, $PageRegions[$Labelflag][$pagenum]['yt'] + 12, 20, 8, 'JPG', 'javascript:void(0)', '', true, 150, '', false, false, 0, false, false, false);
        }
        $this->printCustomsHeaderBarcode($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
        $this->printCustomsbody($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
        $this->printCustomsfooter($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
    }

    public function printCustomsHeaderBarcode($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf) {
        $pdf->write1DBarcode($agentNo, 'C128', $PageRegions[$Labelflag][$pagenum]['xt'] + 45, $PageRegions[$Labelflag][$pagenum]['yt'] + 1, 55, 20, 1, $PageRegions["1DBarcode"]["noborder"], 'N');
    }

    public function printCustomsbody($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf) {
        $pdf->SetFont('helvetica', '', 7);
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 20);
        $pdf->MultiCell(43, 22, "FROM:UUCH
	Building 2 YouQi warehouse ShanCheng logistics park Tangtou  avenue  Shiyan street Baoan District ShenZhen GuangDong China 518108
	PHONE: 075588605979", 0, 'L', 1, 1, '', '', true);
        //$pdf->Ln(-1);
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 40);
        $pdf->Cell(44, 5.5, 'Fees(US $): ', 1, 0, 'L', 0, '', 0);
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 45.5);
        $pdf->SetX($PageRegions[$Labelflag][$pagenum]['xt'] + 1);
        $pdf->Cell(44, 5.5, 'Certificate No. ', 1, 0, 'L', 0, '', 0);
        $pdf->SetFont('helvetica', '', 8);
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 45, $PageRegions[$Labelflag][$pagenum]['yt'] + 20);
        $pdf->MultiCell(54, 31, "SHIP TO: {$billItem->Consignee}
        {$billItem->conAdd} 
        {$billItem->UserCity->ename} {$billItem->conPostCode} ", 1, 'L', 1, 1, '', '', true);
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 45, $PageRegions[$Labelflag][$pagenum]['yt'] + 42);
        $pdf->Cell(54, 10, "PHONE: {$billItem->conTel}", 0, 'L', 1, 0, '', '', 0);
        $pdf->SetFont('helvetica', '', 8);
        $tbl = <<<EOT
<table border="1" width="100%">
    <tr>
        <td align = "center" valign="middle" width="25" height="15">No</td>
        <td align = "center" valign="middle" width="25">Qty</td>
        <td align = "center" valign="middle" width="135">Description of Contents</td>
		<td align = "center" valign="middle" width="37">Kg.</td>
		<td align = "center" valign="middle" width="55">Val(US $)</td>
		<td align = "center" valign="middle" width="70">Goods Origin</td>
    </tr>
EOT;
        $goods_weight = 0;
        $goods_value = 0;
        $goods_num = 0;
        $batchdescription = "";
            $tbl = $tbl . <<<EOT
	<tr>
        <td align = "center">1</td>
        <td align = "center">1</td>
        <td align = "center" height="95">gift       </td>
		<td align = "center">{$weight}</td>
		<td align = "center">15.0</td>
		<td align = "center">CN</td>
    </tr>
EOT;
        $tbl = $tbl . <<<EOT
    <tr>
        <td align = "center" height="15">&nbsp;</td>
        <td align = "center">1</td>
        <td align = "center">Total Gross Weight (Kg.):</td>
		<td align = "center">{$weight}</td>
		<td align = "center">15.0</td>
		<td align = "center">&nbsp;</td>
    </tr>
</table>
EOT;
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 51);
        $pdf->writeHTML($tbl, true, false, false, false, '');
    }

    public function printCustomsfooter($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf) {
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 86);
        $pdf->SetFont("helvetica","",5);
        $pdf->MultiCell(96, 0, 'I certify the particulars given in this customs declaration are correct. This item does not contain any dangerous article, or articles prohibited by legislation or by postal or customs regulations. I have met all applicable export filing requirements under the Foreign Trade Regulations.', 0, 'L', 1, 1, '', '', true);
        
        $pdf->SetFont('','B',7);
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 2, $PageRegions[$Labelflag][$pagenum]['yt'] + 93);
        $pdf->Cell(76, 0, "Sender is Signature & Date Signed:", 0, 0, 'L', 0, '', 0);
        $pdf->SetFont('','',12);
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 86, $PageRegions[$Labelflag][$pagenum]['yt'] + 92);
        $pdf->Cell(76, 0, "CN22", 0, 0, 'L', 0, '', 0);
    }

    public function print_addpage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf) {
        $pdf->SetXY($PageRegions[$Labelflag][$pagenum]['xt'] + 1, $PageRegions[$Labelflag][$pagenum]['yt'] + 1,true);
        $pdf->MultiCell(98, 97, '', 1, 'C', 1, 1, '', '', true);
    }

    public static function printPDF($Labelflag, $billId, $weight,$agentNo) {
        $billItem = Application_Model_wayBillItem::load($billId);
        if(!$billItem){
            return 0;
        }
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        $resolution= array(100, 100);
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('chris xiao');
        $pdf->SetTitle('print title');
        $pdf->SetSubject('print Tutorial');
        $pdf->SetKeywords('print, PDF, example, guide');
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $pdf->SetAutoPageBreak(false, 0);
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        if (@file_exists($GLOBALS['g_dir_pdf_examples_lang'] . 'eng.php')) {
            require_once($GLOBALS['g_dir_pdf_examples_lang'] . 'eng.php');
            $pdf->setLanguageArray($l);
        }
        $pdf->setJPEGQuality(75);
        $pdf->setCellPaddings(1, 1, 1, 1);
        $pdf->SetFillColor(255, 255, 255);
        $PageRegions = array();
        $PageRegions['X4'][0] = array(
            'xt' => 0,
            'yt' => 0,
        );
        $PageRegions['A4'][0] = array(
            'xt' => 0,
            'yt' => 0,
        );
        $PageRegions['A4'][1] = array(
            'xt' => 0,
            'yt' => 99,
        );
        $PageRegions['A4'][2] = array(
            'xt' => 0,
            'yt' => 99,
        );
        $PageRegions['A4'][3] = array(
            'xt' => 106,
            'yt' => 99,
        );
        $PageRegions['A4'][4] = array(
            'xt' => 0,
            'yt' => 198,
        );
        $PageRegions['A4'][5] = array(
            'xt' => 106,
            'yt' => 198,
        );
        $PageRegions['1DBarcode']['noborder'] = array(
            'position' => '',
            'align' => 'R',
            'stretch' => false,
            'fitwidth' => true,
            'cellfitalign' => '',
            'border' => false,
            'hpadding' => 'auto',
            'vpadding' => 'auto',
            'fgcolor' => array(0, 0, 0),
            'bgcolor' => false, //array(255,255,255),
            'text' => true,
            'font' => 'helvetica',
            'fontsize' => 8,
            'stretchtext' => 0
        );
        $PageRegions['1DBarcode']['border'] = array(
            'position' => '',
            'align' => 'R',
            'stretch' => false,
            'fitwidth' => true,
            'cellfitalign' => '',
            'border' => true,
            'hpadding' => 'auto',
            'vpadding' => 'auto',
            'fgcolor' => array(0, 0, 0),
            'bgcolor' => false, //array(255,255,255),
            'text' => true,
            'font' => 'helvetica',
            'fontsize' => 8,
            'stretchtext' => 0
        );
        $pagenum = 0;
        $tcpdf = new Uuch_Tcpdf();
        if ($Labelflag == "X4") {
            $pdf->AddPage('P', $resolution);
            $tcpdf->printEUBmainPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
            $pdf->AddPage('P', $resolution);
            $tcpdf->printEUBCustomsPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
        } elseif ($Labelflag == "A4") {
            if ($pagenum % 6 == 0) {
                $pdf->AddPage('P', $Labelflag);
                $pagenum = 0;
            }
            $tcpdf->printEUBmainPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
            $pagenum = $pagenum + 1;

            $tcpdf->printEUBCustomsPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
        }
        $pdf->Output($billItem->BillNo.'.pdf', 'D');
    }
    public static function printPDFByBillId($Labelflag, $billId) {
        $billItem = Application_Model_wayBillItem::load($billId);
        if(!$billItem){
            return 0;
        }
        $weight = $billItem->weight/1000;
        $agentNo = $billItem->agentNo;
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
        $resolution= array(100, 100);
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('chris xiao');
        $pdf->SetTitle('print title');
        $pdf->SetSubject('print Tutorial');
        $pdf->SetKeywords('print, PDF, example, guide');
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $pdf->SetAutoPageBreak(false, 0);
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        if (@file_exists($GLOBALS['g_dir_pdf_examples_lang'] . 'eng.php')) {
            require_once($GLOBALS['g_dir_pdf_examples_lang'] . 'eng.php');
            $pdf->setLanguageArray($l);
        }
        $pdf->setJPEGQuality(75);
        $pdf->setCellPaddings(1, 1, 1, 1);
        $pdf->SetFillColor(255, 255, 255);
        $PageRegions = array();
        $PageRegions['X4'][0] = array(
            'xt' => 0,
            'yt' => 0,
        );
        $PageRegions['A4'][0] = array(
            'xt' => 0,
            'yt' => 0,
        );
        $PageRegions['A4'][1] = array(
            'xt' => 0,
            'yt' => 99,
        );
        $PageRegions['A4'][2] = array(
            'xt' => 0,
            'yt' => 99,
        );
        $PageRegions['A4'][3] = array(
            'xt' => 106,
            'yt' => 99,
        );
        $PageRegions['A4'][4] = array(
            'xt' => 0,
            'yt' => 198,
        );
        $PageRegions['A4'][5] = array(
            'xt' => 106,
            'yt' => 198,
        );
        $PageRegions['1DBarcode']['noborder'] = array(
            'position' => '',
            'align' => 'R',
            'stretch' => false,
            'fitwidth' => true,
            'cellfitalign' => '',
            'border' => false,
            'hpadding' => 'auto',
            'vpadding' => 'auto',
            'fgcolor' => array(0, 0, 0),
            'bgcolor' => false, //array(255,255,255),
            'text' => true,
            'font' => 'helvetica',
            'fontsize' => 8,
            'stretchtext' => 0
        );
        $PageRegions['1DBarcode']['border'] = array(
            'position' => '',
            'align' => 'R',
            'stretch' => false,
            'fitwidth' => true,
            'cellfitalign' => '',
            'border' => true,
            'hpadding' => 'auto',
            'vpadding' => 'auto',
            'fgcolor' => array(0, 0, 0),
            'bgcolor' => false, //array(255,255,255),
            'text' => true,
            'font' => 'helvetica',
            'fontsize' => 8,
            'stretchtext' => 0
        );
        $pagenum = 0;
        $tcpdf = new Uuch_Tcpdf();
        if ($Labelflag == "X4") {
            $pdf->AddPage('P', $resolution);
            $tcpdf->printEUBmainPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
            $pdf->AddPage('P', $resolution);
            $tcpdf->printEUBCustomsPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
        } elseif ($Labelflag == "A4") {
            if ($pagenum % 6 == 0) {
                $pdf->AddPage('P', $Labelflag);
                $pagenum = 0;
            }
            $tcpdf->printEUBmainPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
            $pagenum = $pagenum + 1;

            $tcpdf->printEUBCustomsPage($pagenum, $PageRegions, $Labelflag, $billItem, $weight,$agentNo, $pdf);
        }
        $pdf->Output($billItem->BillNo.'.pdf', 'D');
    }
}

?>
